import { NodeSize } from '../config'

export default function httpPost(flow) {
  flow.register('HttpPost', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M828.952381 260.87619c0-26.819048-21.942857-46.32381-46.32381-46.323809H426.666667c-58.514286 0-90.209524 31.695238-90.209524 90.209524v373.028571H487.619048v41.447619h-229.180953c-26.819048 0-46.32381 21.942857-46.323809 46.32381 0 26.819048 21.942857 46.32381 46.323809 46.323809h368.152381c58.514286 0 90.209524-31.695238 90.209524-90.209524V280.380952H755.809524v26.819048h26.819047c26.819048 0 46.32381-21.942857 46.32381-46.32381z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M782.628571 170.666667H426.666667C343.771429 170.666667 292.571429 221.866667 292.571429 304.761905v373.028571h-39.009524c-48.761905 0-87.771429 39.009524-87.771429 87.771429S204.8 853.333333 253.561905 853.333333h368.152381c82.895238 0 131.657143-51.2 131.657143-131.657143V348.647619H780.190476c48.761905 0 87.771429-39.009524 87.771429-87.771429 2.438095-48.761905-36.571429-90.209524-85.333334-90.209523zM755.809524 307.2v-26.819048h-41.447619v441.295238c0 58.514286-31.695238 90.209524-90.209524 90.209524H253.561905c-26.819048 0-46.32381-21.942857-46.32381-46.323809 0-26.819048 21.942857-46.32381 46.32381-46.32381h229.180952v-41.447619h-151.161905V304.761905c0-58.514286 31.695238-90.209524 90.209524-90.209524H780.190476c26.819048 0 46.32381 21.942857 46.32381 46.323809 0 26.819048-21.942857 46.32381-46.32381 46.32381h-24.380952z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M543.695238 394.971429v168.228571c0 26.819048-4.87619 29.257143-43.885714 65.828571l-19.504762-19.504761c31.695238-29.257143 31.695238-31.695238 31.695238-46.32381v-168.228571h31.695238z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          'HTTP Post查询'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
